runOnStartup(async runtime => {
    lib.addon_cam.debugcam = false
    runtime.objects.cam.addEventListener("instancecreate", (e) => {
        lib.addon_cam["click:move:camera"]()
        //lib.godcam["drag:move:camera"]()
        runtime.addEventListener("tick", () => {
            lib.addon_cam["cam:regis"]()
            

        })
    })
})

lib.addon_cam= {

    "cam:regis": () => {
        if (!lib.addon_cam.debugcam) return
        var _camsprite = runtime.objects.cam?.getFirstInstance()
        runtime.layout.scrollTo(_camsprite.x, _camsprite.y)
    },

    "click:move:camera": () => {
        lib.addEventListener("_mouseclick", function mouseclick() {
            /**
             * @type {IMoveToBehaviorInstance}
             */
            var _cammovebehavior = runtime.objects.cam?.getFirstInstance().behaviors.MoveTo
            _cammovebehavior.moveToPosition(runtime.mouse.getMouseX("main"), runtime.mouse.getMouseY("main"), true)
            var _camsprite = runtime.objects.cam.getFirstInstance()
            _camsprite.isVisible = false

        })
    },

    "drag:move:camera": () => {
        lib.addEventListener("_mousemidclicktick", function __mousemidclicktick() {
            var _camsprite = runtime.objects.cam?.getFirstInstance()
            _camsprite.isVisible = false
            var MOUSE_X = runtime.mouse.getMouseX("main")
            var MOUSE_Y = runtime.mouse.getMouseY("main")
            /*       _camsprite.x = MOUSE_X
             _camsprite.y = MOUSE_Y*/
            /**
             *
             * @type {IMoveToBehaviorInstance}
             * @private
             */
            var _cammovebehavior = runtime.objects.cam?.getFirstInstance().behaviors.MoveTo
            _cammovebehavior.maxSpeed = 10000
            _cammovebehavior.moveToPosition(runtime.mouse.getMouseX("main"), runtime.mouse.getMouseY("main"), true)

        })
    }
}